package com.mushuilingfeng.ddd.user.domain.user.loginfilter;

import com.mushuilingfeng.ddd.framework.AsSpringBean;
import com.mushuilingfeng.ddd.framework.factory.DomainRepositoryFactory;
import com.mushuilingfeng.ddd.user.domain.IDataCover;
import com.mushuilingfeng.ddd.user.domain.user.IUserLoginFilter;
import com.mushuilingfeng.ddd.user.domain.user.dto.AbstractLoginDto;
import com.mushuilingfeng.ddd.user.domain.user.dto.PasswordLoginDto;
import com.mushuilingfeng.ddd.user.domain.user.entity.User;
import com.mushuilingfeng.ddd.user.domain.user.enums.LoginTypeEnum;
import com.mushuilingfeng.ddd.user.domain.user.repository.IUserLoginLogRepository;
import com.mushuilingfeng.ddd.user.domain.user.vo.UserLoginLog;
import lombok.extern.slf4j.Slf4j;

/**
 * 登陆日志记录过滤器
 *
 * @author 沐水淋风
 * @date 2024/10/3
 */
@AsSpringBean
@Slf4j
public class LoginLogRecordFilter implements IUserLoginFilter {
    
    @Override
    public int order() {
        return -1;
    }
    
    @Override
    public void filter(User user, AbstractLoginDto loginParams) {
        log.info("record login log:{}", loginParams);
        UserLoginLog userLoginLog = IDataCover.INSTANCE.toUserLoginLog(loginParams, user.getId(), loginParams.getLoginType());
        DomainRepositoryFactory.getRepository(IUserLoginLogRepository.class).save(userLoginLog);
    }
    
}
